package com.taptech.doufu.ui.viewholder.personalcenter;

import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.MineContentTitleBean;
import com.taptech.doufu.services.personalcenter.AccountService;

/**
 * 个人内容的类型题头布局
 * 
 * @author Diaobao22
 * 
 */
public class MessageTypeViewHolder extends BaseAdapterViewHolder implements
		OnClickListener {
	// 就是布局从左到右3个textview
	public TextView textview1;
	public TextView textview2;
	public TextView textview3;
	private LinearLayout enterImage;
	private MineContentTitleBean mBean;

	public MessageTypeViewHolder(Context context, int position) {
		super(context, position, R.layout.message_type_viewholder);
		// TODO Auto-generated constructor stub
	}

	public MessageTypeViewHolder(Context context, int position, int layoutId) {
		super(context, position, layoutId);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void getChildView(View convertView) {
		textview1 = (TextView) convertView
				.findViewById(R.id.messagetype_enter_text1);
		textview2 = (TextView) convertView
				.findViewById(R.id.messagetype_enter_text2);
		textview3 = (TextView) convertView
				.findViewById(R.id.messagetype_enter_text3);
		enterImage = (LinearLayout) convertView
				.findViewById(R.id.messagetype_enter_image);
		textview3.setOnClickListener(this);

		enterImage.setOnClickListener(this);
	}

	@Override
	public void setChildView(Object object,int singlePage) {
		mBean = (MineContentTitleBean) object;
		if (mBean == null) {
			return;
		}
		if (mBean.getTypeString() != null) {
			if (AccountService.getInstance().isUserSelf(mBean.getUserId())) {
				textview1.setText("我的" + mBean.getTypeString());
			} else {
				textview1.setText("TA的" + mBean.getTypeString());
			}

			textview2.setText("(" + mBean.getTypeContentCount() + ")");
			textview3.setText("所有" + mBean.getTypeString());
		}
		if (mBean.getTypeString().equals("群组")) {
			if (AccountService.getInstance().isUserSelf(mBean.getUserId())) {
				textview1.setText("我所创建的群组");
			} else {
				textview1.setText("TA所创建的群组");
			}
			textview2.setText("");
			textview3.setText("");
		}

	}

	@Override
	public void setChildView(Object object, String keyWord,int singlePage) {
		setChildView(object,singlePage);
	}

	@Override
	public void setHandler(Handler handler) {

	}

	@Override
	public void onClick(View v) {
		if (mBean == null) {
			return;
		}

	}

	@Override
	public BaseAdapterViewHolder createViewHolder(Context context, int position) {
		// TODO Auto-generated method stub
		return new MessageTypeViewHolder(context, position);
	}

}
